package org.algorithm.Backtracking.leetcode78;

import java.util.ArrayList;
import java.util.List;

/**
 * 子集问题， 输入的数组中没有重复元素，无需考虑数据重复
 */

public class Solution {

    List<List<Integer>> res = new ArrayList<>();
    List<Integer> item = new ArrayList<>();
    public List<List<Integer>> subsets(int[] nums) {

        backtracking(nums,0);
        return res;
    }

    private void backtracking(int [] nums,int index){
        res.add(new ArrayList<>(item));
        if (index==nums.length){
            return;
        }

        for (int i = index; i < nums.length; i++) {
            item.add(nums[i]);
            backtracking(nums,i+1);
            item.remove(item.size()-1);
        }
    }
}
